import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'

const pathResolve = (dir) => resolve(__dirname,dir)

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
	const env = loadEnv(mode,process.cwd(),'')
	return {
	  plugins: [
		  vue()
		],
	  envPrefix: 'APP_',
	  server:{
		  port: 8080,
		  proxy: {
			  [env.APP_BASE_URL]: {
				  target: env.APP_SERVER,
				  changeOrigin: true,
				  rewrite: (path) => path.replace(env.APP_BASE_URL, env.APP_REPLACE_URL),
			  }
		  }
	  },
	  resolve: {
		  alias: {
			  '@': pathResolve('./src')
		  }
	  },
	  define: {
		  __APP_ENV__: JSON.stringify(env.APP_ENV)
	  }
	}
})
